package com.yllt4cloud.common.ddbase.param;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yllt4cloud.common.ddbase.util.JsonUtil;

import java.util.Map;

/**
 * @description:
 * @author: yaoxj
 * @create: 2020-01-21 17:03
 **/
public class  PageParam<T> extends BaseParam {
    private static final int DEFAULT_PAGE_NO = 1;
    private static final int DEFAULT_PAGE_SIZE = 10;
    private Page<T> page = new Page<>(DEFAULT_PAGE_NO, DEFAULT_PAGE_SIZE);

    public Long getPageNo() {
        return page.getCurrent();
    }

    public Long getPageSize() {
        return page.getSize();
    }

    public void setPageNo(Long pageNo) {
        page.setCurrent(pageNo);
    }

    public void setPageSize(Long pageSize) {
        page.setSize(pageSize);
    }

    /**
     * <p><b>作用：</b>获取分页参数的page</p>
     * <p><b>日期：</b>2016-1-20 下午2:47:43</p>
     * <p><b>作者：</b>yaozq</p>
     *
     * @return
     * @throws
     */
    public Page<T> getPage() {
        return this.page;
    }

    /**
     * <p><b>作用：</b>将参数对象转化为不带分页参数的Map对象</p>
     * <p><b>日期：</b>2016-1-20 下午2:46:57</p>
     * <p><b>作者：</b>yaozq</p>
     *
     * @param obj
     * @return
     * @throws
     */
    public Map<String, Object> getNonPagedMap(Object obj) {
        Map<String, Object> paramMap = JsonUtil.parseMap(obj);

        if (paramMap.containsKey("page"))
            paramMap.remove("page");

        if (paramMap.containsKey("sheBeiId"))
            paramMap.remove("sheBeiId");
        return paramMap;
//		return JsonUtil.parseMap(JsonUtil.getShowJson(this));
    }

    /**
     * <p><b>作用：</b>将对象转为有page的map参数</p>
     * <p><b>日期：</b>2016-1-28 上午11:26:57</p>
     * <p><b>作者：</b>panw</p>
     *
     * @param obj
     * @return
     * @throws
     */
    public Map<String, Object> getMapPage(Object obj) {
        Map<String, Object> paramMap = JsonUtil.parseMap(obj);
        paramMap.put("page", getPage());
        return paramMap;
//		return JsonUtil.parseMap(JsonUtil.getShowJson(this));
    }
}
